import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import './common/css/font.css'
// 引入粒子特效
import VueParticles from 'vue-particles'
import axios from 'axios'
import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'
Vue.use(VueParticles)
Vue.use(ElementUI)
Vue.use(mavonEditor)
Vue.config.productionTip = false
axios.defaults.baseURL = 'http://localhost:8080';
// 使用时axios
Vue.prototype.$http = axios;
new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
//判断是否登录
router.beforeEach((to, from, next) => {
  /**
   * 未登录则跳转到登录页
   * 未登录跳转到登录页,也可以通过axios的响应拦截器去实现,但是会先在当前页面渲染一下,再跳转到登录页,会有个闪动的现象
   * 这里通过路由守卫的方式,不会在当前页闪现一下,但是需要在每个路由组件添加一个是否需要登录的标识位,如本项目中的requireAuth字段
   */
  if (to.matched.some((auth) => auth.meta.requireAuth)) {
      let token = localStorage.getItem("token");
      if (token) {
          next();
      } else {
          next({
              path: "/Login"
          });
      }
  } else {
      next();
  }
})